//========encoding:utf-8=========
/*
 * @describe:  三目运算符
 * @author:mhao
 * @copyright:chinasoft.cn
 * @date:2020年2月10日   下午7:02:37
 */
package edu.chinasoft.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

import edu.chinasoft.util.HttpServeltRequestExtend;

public class Filter01 implements Filter{
	private static Logger logger = Logger.getLogger(Filter01.class);
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		logger.debug("Filter01>>>destroy  start……");
		logger.debug("Filter01>>>destroy  end……");
	}

	@Override
	public void doFilter(ServletRequest requeset, ServletResponse response, FilterChain filterChain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		/* 多态    父类转子类    强制转
		 * Servlet里doGet   doPost参数的类型
		 */
		logger.debug("Filter01>>>doFilter  start……");
		//类型转换
		HttpServletRequest request01=(HttpServletRequest)requeset;
		HttpServletResponse response01=(HttpServletResponse)response;		//过滤器的业务逻辑代码
		//解决的是post请求的乱码
		request01.setCharacterEncoding("UTF-8");
		//解决get请求的乱码
		HttpServeltRequestExtend request02=new  HttpServeltRequestExtend(request01);
		//解决响应的乱码
		response01.setContentType("text/html;charset=utf-8");
		//传递的实参必须是类型转换后
		filterChain.doFilter(request02,response01);
		logger.debug("Filter01>>>doFilter  end……");
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		logger.debug("Filter01>>>init  start……");
		logger.debug("Filter01>>>init  end……");
	}

}
